package com.five.controller.backstage;

import com.five.dao.backstage.CSTongjiDao;
import com.five.dao.backstage.CountDao;
import com.five.entity.backstage.CSTongji;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author:常鹏宇
 * @Description
 * @date:2020/12/4
 */
@RestController
@RequestMapping("CSTongji")
public class CSTongjiController {
    @Autowired
    private CSTongjiDao csTongjiDao;

    @RequestMapping("selectTongji")
    public List<Map> selectTongji(CSTongji csTongji) {
        List<Map> maps = csTongjiDao.selectTongji(csTongji);
        List<Map> mapList = csTongjiDao.selectPType();

        //循环取出统计图数据主体
        List<Map> maxList = new ArrayList();
        for (int i = 0; i < mapList.size(); i++) {
            Map dataMap = new HashMap();
            //数据主体是key value的键值对 直接封装
            dataMap.put("name", mapList.get(i).get("name"));
            dataMap.put("type", "bar");
            // dataMap.put("barGap", 0);
            dataMap.put("label", "labelOption");

            List datalist = new ArrayList();
            for (int j = 1; j <= 12; j++) {
                String s = j + "";
                for (Map map : maps) {
                    String name = map.get("name") + "";
                    String lname = mapList.get(i).get("name") + "";
                    String mon = map.get("month") + "";
                    //System.out.println(name+"=="+lname+"=="+mon+"=="+j);
                    if (name.equals(lname) && mon.equals(s)) {
                        datalist.add((j - 1), map.get("money"));
                    }
                }
                if (datalist.size() < 12) {
                    datalist.add(0);
                }
            }
            dataMap.put("data", datalist);
            maxList.add(dataMap);
        }
        return maxList;
    }

    //查询设施类型
    @RequestMapping("tongjiType")
    public List tongjiType(){
        List<Map> mapList = csTongjiDao.tongjiType();
        List list = new ArrayList();
        for (int i = 0; i < mapList.size(); i++) {
            list.add(mapList.get(i).get("name"));
        }
        return list;
    }
}
